package us.efiling.gaje2.conf;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

public class ConfigurationFactoryBean implements FactoryBean<Resource>{

	Logger log = Logger.getLogger(ConfigurationFactoryBean.class);
	
	@Override
	public Resource getObject() throws Exception {
		
		String str = System.getProperty("efiling.gaje2.conf");
		if(str == null || str.trim().equalsIgnoreCase(""))
		{
			log.warn("couldn't find efiling.gaje2.conf. Using classpath:/database.properties");
			return new ClassPathResource("/database.properties");
		}
		else
		{
			log.info("Found efiling.gaje2.conf at " + System.getProperty("efiling.gaje2.conf").replace("file://",""));
			return new FileSystemResource(System.getProperty("efiling.gaje2.conf").replace("file://","") );
		}
	}

	@Override
	public Class<?> getObjectType() {
		return Resource.class;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

}
